<?php

/*************************************************************************

	FILE INCLUDE

**************************************************************************/
include_once '../lib/Template.class.php';
$debug_mode_value = 0;
checkLogin();



/*************************************************************************

	USER SCRIPT

***************************************************************************/
$userscript =<<<js
    <script type="text/javascript">
        <!--
        function submitForm(){
        	dt1=document.getElementById("search_date_start").value;
        	dt2=document.getElementById("search_date_end").value;
        	if(isValidDate(dt1) && isValidDate(dt2))
			{
				document.getElementById("searchForm").submit();
			}else{
				alert("date only!");
			}
        }
		function isValidDate(iDate) {
		  if( iDate.length != 8 ) {
		    return false;
		  }
		  oDate = new Date();
		  oDate.setFullYear(iDate.substring(0, 4));
		  oDate.setMonth(parseInt(iDate.substring(4, 6)) - 1);
		  oDate.setDate(iDate.substring(6));
		  if( oDate.getFullYear()     != iDate.substring(0, 4)
		      || oDate.getMonth() + 1 != iDate.substring(4, 6)
		      || oDate.getDate()      != iDate.substring(6) ) {
		    return false;
		  }
		  return true;
		}
        //-->
    </script>
js;


/*************************************************************************

		PAGE MAIN PROCESS

***************************************************************************/
(!empty($_REQUEST['search_date_start']))? $search_date_start = $_REQUEST['search_date_start'] : $search_date_start = date("Ymd",mktime(0,0,0,date("m"),date("d")-7,date("Y")));
(!empty($_REQUEST['search_date_end']))? $search_date_end = $_REQUEST['search_date_end'] : $search_date_end = date("Ymd");

$db->conn();
$query = "select STATUS_DT,STATUS_REGISTER,USER_NM, sum(save_cnt) as SAVE_CNT,sum(check_cnt) as CHECK_CNT, row_cnt as ROW_CNT  from
		  (
		  select STATUS_REGISTER_3 as STATUS_REGISTER,STATUS_DT_3 as STATUS_DT ,count(*) as save_cnt , 0 as check_cnt FROM cluster_work_tb
		  WHERE STATUS_DT_3 BETWEEN '$search_date_start' AND '$search_date_end'
		  group by STATUS_DT_3,  STATUS_REGISTER_3
		  union all
		  select STATUS_REGISTER_6 as STATUS_REGISTER,STATUS_DT_6 as STATUS_DT,0 as save_cnt,count(*) as check_cnt FROM cluster_work_tb
		  WHERE STATUS_DT_6 BETWEEN '$search_date_start' AND '$search_date_end'
		  group by STATUS_DT_6,  STATUS_REGISTER_6
		  ) temp
		  left outer join user_tb
		  on temp.STATUS_REGISTER = user_tb.USER_CD
		    left outer join
		      (select STATUS_DT as DT, count(*) as ROW_CNT from(
		        select STATUS_DT,STATUS_REGISTER,USER_NM, sum(save_cnt),sum(check_cnt) from
		          (
		          select STATUS_REGISTER_3 as STATUS_REGISTER,STATUS_DT_3 as STATUS_DT ,count(*) as save_cnt , 0 as check_cnt FROM cluster_work_tb
		          WHERE STATUS_DT_3 BETWEEN '$search_date_start' AND '$search_date_end'
		          group by STATUS_DT_3,  STATUS_REGISTER_3
		          union all
		          select STATUS_REGISTER_6 as STATUS_REGISTER,STATUS_DT_6 as STATUS_DT,0 as save_cnt,count(*) as check_cnt FROM cluster_work_tb
		          WHERE STATUS_DT_6 BETWEEN '$search_date_start' AND '$search_date_end'
		          group by STATUS_DT_6,  STATUS_REGISTER_6
		          ) temp1
		          left outer join user_tb
		          on temp1.STATUS_REGISTER = user_tb.USER_CD
		        group by STATUS_DT,STATUS_REGISTER,USER_NM
		       ) A
		       GROUP BY STATUS_DT
		     ) temp2
		    on temp.STATUS_DT = temp2.DT
		group by STATUS_DT,STATUS_REGISTER,USER_NM
		order by STATUS_DT DESC,STATUS_REGISTER ";
$list = $db->select($query);


$total1=$db->assoc("SELECT
			SUM(if(CLUSTER_ST=3,1,0)) as save_cnt,
			SUM(if(CLUSTER_ST=6,1,0)) as check_cnt
			from cluster_tb a
			  left outer join candidate_tb b
			  on a.CLUSTER_CD = b.CLUSTER_CD
			where a.CLUSTER_ST in(3,6)");
$total2=$db->assoc("SELECT
			SUM(if(CLUSTER_ST=3,1,0)) as save_cnt,
			SUM(if(CLUSTER_ST=6,1,0)) as check_cnt
			from cluster_tb
			where CLUSTER_ST in(3,6)");

$db->close();


/*************************************************************************

	TEMPLATE PROCESS

***************************************************************************/
$body = "WorkReport.html";

$tpl = new Template();
$tpl->setDefine($body);

$tpl->assign("list", $list);
$tpl->assign("total1", $total1);
$tpl->assign("total2", $total2);
$tpl->assign("temp_cd", 0);
$tpl->assign("search_date_start",$search_date_start);
$tpl->assign("search_date_end",$search_date_end);

$tpl->setPrint();





/*************************************************************************

	AJAX FUNCTION : Template_ function

***************************************************************************/



















?>
